from datetime import datetime
from PyQt5.QtWidgets import QPushButton,QWidget,QHBoxLayout,QDateEdit,QLabel
from PyQt5 import QtCore

class SlideButton(QPushButton):
    __STYLE_NORMAL = "QPushButton{border-radius: 1px;background-color:#d9d9d9; border:1px groove gray;border-style:solid}"
    __STYLE_ACTIVE = "QPushButton{border-radius: 1px;background-color:#9fc5e8; border:1px groove gray;border-style:solid}"

    def __init__(self,*args, **kwargs):
        super(SlideButton, self).__init__(*args,**kwargs)
        self.setStyleSheet(SlideButton.__STYLE_NORMAL);

    def setActive(self,active:bool):
        if active:
            self.setStyleSheet(SlideButton.__STYLE_ACTIVE)
        else:
            self.setStyleSheet(SlideButton.__STYLE_NORMAL)




class DateRange(QWidget):
    def __init__(self,title, *args, **kwargs):
        super(QWidget, self).__init__(*args, **kwargs)
        box = QHBoxLayout()
        self.start_date = QDateEdit()
        self.end_date = QDateEdit()
        self.start_date.setCalendarPopup(True)
        self.end_date.setCalendarPopup(True)
        self.start_date.setDate(datetime.today())
        self.end_date.setDate(datetime.today())
        self.set_date_display_format('yyyy-MM-dd')
        self.title = QLabel(title+":")
        box.addWidget(self.title)
        box.addWidget(self.start_date,stretch=1)
        box.addWidget(QLabel("-"))
        box.addWidget(self.end_date,stretch=1)
        self.setLayout(box)

    def get_start_date(self):
        return self.start_date.text()

    def get_end_date(self):
        return self.end_date.text()

    def get_dates(self):
        return [
            self.start_date.text(),
            self.end_date.text()
        ]

    def set_date_display_format(self,format):
        self.start_date.setDisplayFormat(format)
        self.end_date.setDisplayFormat(format)